<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <p>侦听器的应用场景：数据变化时执行异步或开销比较大的操作</p>
        <input type="text" name="" id="" v-model.lazy='uName'>
        {{tip}}
    </div>
</body>
<script src="js/vue.js"></script>
<script>

    var vm = new Vue({
        el:'#app',
        data:{
            msg:'orange',
            num:100,
            uName:'',
            tip:''
        },
        methods: {
            checkName:function(val){
                var that = this
                setTimeout(function(){
                    if(val == 'admin'){
                        that.tip = '用户名已经存在'
                    }
                    else{
                        that.tip = '验证通过'
                    }
                },2000)
            }
        },
        watch: {
            uName:function(val){
                this.checkName(val)
                this.tip = '正在验证...'
            }

        },
    })

</script>
</html>